import { DateTime } from 'luxon'
import {BaseModel, beforeCreate, BelongsTo, column} from '@ioc:Adonis/Lucid/Orm'
import uuid from 'uuid-v4'
import {belongsTo} from "@adonisjs/lucid/build/src/Orm/Decorators";
import Skus from "App/Models/Skus";
export default class Param extends BaseModel {
  public static table = 'tb_params'
  @column({ isPrimary: true })
  public id: string
  @column()
  public skuId: string;
  @column()
  public name: string;
  @column()
  public value: string
  @column.dateTime({ autoCreate: true })
  public createdAt: DateTime

  @column.dateTime({ autoCreate: true, autoUpdate: true })
  public updatedAt: DateTime;
  @belongsTo(() => Skus)
  public spu: BelongsTo<typeof Skus>
  @beforeCreate()
  public static assignUuid(param: Param) {
    param.id = uuid()
  }
}
